pull: Tweak status line again, do what git does
authorColin Walters <walters@verbum.org>
Wed, 24 Jul 2013 22:20:19 +0000 (18:20 -0400)
committerColin Walters <walters@verbum.org>
Wed, 24 Jul 2013 22:20:19 +0000 (18:20 -0400)
Almost, we don't have bytes transferred.  And we lie about percentages
since as metadata comes in the total number of objects to fetch goes
up.

src/libostree/ostree-repo-pull.c

index a270d1c044872e44b79b0c2554e96db18198423e..8837b378f2456b39cc350e98d989f6df65a71636 100644 (file)
@@ -194,26 +194,29 @@ uri_fetch_update_status (gpointer user_data)
  
   status = g_string_new ("");
 
-  if (!pull_data->metadata_scan_idle)
-    g_string_append_printf (status, "scan: %u; ",
-                            g_atomic_int_get (&pull_data->n_scanned_metadata));
-
+  outstanding_fetches = pull_data->n_outstanding_content_fetches + pull_data->n_outstanding_metadata_fetches;
   outstanding_stages = pull_data->n_outstanding_content_stage_requests + pull_data->n_outstanding_metadata_stage_requests;
-  if (outstanding_stages > 0)
-    g_string_append_printf (status, "writing: %u; ", outstanding_stages);
 
-  outstanding_fetches = pull_data->n_outstanding_content_fetches + pull_data->n_outstanding_metadata_fetches;
   if (outstanding_fetches)
     {
-      g_string_append_printf (status, "fetch: %u/%u meta %u/%u; ",
-                              pull_data->n_fetched_metadata,
-                              pull_data->n_requested_metadata,
-                              pull_data->n_fetched_content,
-                              pull_data->n_requested_content);
-
-      fetcher_status = ostree_fetcher_query_state_text (pull_data->fetcher);
-      g_string_append (status, fetcher_status);
+      guint64 bytes_transferred = ostree_fetcher_bytes_transferred (pull_data->fetcher);
+      guint fetched = pull_data->n_fetched_metadata + pull_data->n_fetched_content;
+      guint requested = pull_data->n_requested_metadata + pull_data->n_requested_content;
+      gs_free char *formatted_bytes_transferred = NULL;
+
+      formatted_bytes_transferred = g_format_size_full (bytes_transferred, 0);
+
+      g_string_append_printf (status, "Receiving objects: %u%% (%u/%u) %s",
+                              (guint)((((double)fetched) / requested) * 100),
+                              fetched, requested, formatted_bytes_transferred);
     }
+  else if (outstanding_stages > 0)
+    g_string_append_printf (status, "Writing objects: %u", outstanding_stages);
+  else if (!pull_data->metadata_scan_idle)
+    g_string_append_printf (status, "Scanning metadata: %u",
+                            g_atomic_int_get (&pull_data->n_scanned_metadata));
+  else
+    g_string_append_printf (status, "Idle");
 
   gs_console_begin_status_line (gs_console_get (), status->str, NULL, NULL);